﻿using System;
using System.Collections.Generic;
using System.Text;
using Sinacor.Infra.Service.Common;
using PSE.ProcessManager.Server.Process.Security;
using Sinacor.Infra.Core.ProcessManager.Server.Security;
using Sinacor.Infra.Service.Security.Services;
using Sinacor.Process.Bovespa.Distribuicao.Server.Bovespa.Calendario.CalendarioBolsa;

namespace Sinacor.Process.Bovespa.Distribuicao.Server.Communication
{
    public class CalendarioBolsa : BaseCommunication
    {
        #region Construtor

        public CalendarioBolsa()
            : base(AuthenticationContext<SinacorAuthenticationData>.Current.AuthenticationData.LoginName, AuthenticationContext<SinacorAuthenticationData>.Current.AuthenticationData.Password, AuthenticationContext<SinacorAuthenticationData>.Current.AuthenticationData.CompanyId)
        {
        }

        #endregion

        #region Métodos Públicos

        public List<ProcessEntity.Calendario> ConsultarCalendarios(ProcessEntity.Parameter.FiltroCalendario entity)
        {
            ICalendarioBolsa servico = null;
            Translator.DataContractToProcessEntity.CalendarioBolsa translatorResponse = null;
            Translator.ProcessEntityToDataContract.CalendarioBolsa translatorRequest = null;
            List<ProcessEntity.Calendario> retorno = null;

            try
            {
                using (ServiceInstance<ICalendarioBolsa> service = new ServiceInstance<ICalendarioBolsa>())
                {
                    servico = service.TryGetInstance(this.LoginName, this.Password, this.CompanyId);
                    translatorResponse = new Translator.DataContractToProcessEntity.CalendarioBolsa();
                    translatorRequest = new Translator.ProcessEntityToDataContract.CalendarioBolsa();
                    retorno = translatorResponse.ToCalendario(servico.ConsultarCalendarios(translatorRequest.ToFiltroCalendarioRequest(entity)));
                }
            }
            catch (Exception ex)
            {
                base.HandleFault(ex);
            }

            return retorno;
        }

        #endregion
    }
}
